﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;


namespace Vms.DB
{
    public class DB
    {
        public DB() { }
        string conn = ConfigurationManager.AppSettings["connectSamisDB"];
        string conn_data = ConfigurationManager.AppSettings["connectVoice1506"];
        private static Util m_util = new Util();

        public void InsertReQuestTbl(Util.TSession m_tsession)
        {
            try
            {
                SqlConnection ObjCon = new SqlConnection(conn);
                ObjCon.Open();
                SqlCommand sqlcommand = new SqlCommand("USSD_Insert_RequestTbl", ObjCon);
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@RequestTime", SqlDbType.DateTime));
                sqlcommand.Parameters["@RequestTime"].Value = m_tsession.StartTime;
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@MSISDN", SqlDbType.NChar));
                sqlcommand.Parameters["@MSISDN"].Value = m_tsession.UserMSISDN;
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@SessionID", SqlDbType.NChar));
                sqlcommand.Parameters["@SessionID"].Value = m_tsession.SessionID;
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@IPRequest", SqlDbType.NChar));
                sqlcommand.Parameters["@IPRequest"].Value = m_tsession.IP;
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@User_ID", SqlDbType.NChar));
                sqlcommand.Parameters["@User_ID"].Value = m_tsession.User_ID;
                sqlcommand.CommandType = CommandType.StoredProcedure;
                sqlcommand.ExecuteNonQuery();
                sqlcommand.Dispose();
                ObjCon.Close();
            }
            catch (Exception e)
            {
                m_util.write_log("InsertReQuestTbl:" + e.ToString(), 3);
                InsertErrorLog(e.ToString(), "DB", "InsertReQuestTbl", 2);
            }
        }
        public void UpdateReQuestTbl(Util.TSession m_tsession)
        {
            try
            {
                SqlConnection ObjCon = new SqlConnection(conn);
                ObjCon.Open();
                SqlCommand sqlcommand = new SqlCommand("USSD_Update_RequestTbl", ObjCon);
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@MSISDN", SqlDbType.NChar));
                sqlcommand.Parameters["@MSISDN"].Value = m_tsession.UserMSISDN;
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@SessionID", SqlDbType.NChar));
                sqlcommand.Parameters["@SessionID"].Value = m_tsession.SessionID;
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@IPRequest", SqlDbType.NChar));
                sqlcommand.Parameters["@IPRequest"].Value = m_tsession.IP;
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@User_ID", SqlDbType.NChar));
                sqlcommand.Parameters["@User_ID"].Value = m_tsession.User_ID;
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ServiceList", SqlDbType.NChar));
                sqlcommand.Parameters["@ServiceList"].Value = m_tsession.ServiceList;
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@KeyPress", SqlDbType.NChar));
                sqlcommand.Parameters["@KeyPress"].Value = m_tsession.KeyPress;
                sqlcommand.CommandType = CommandType.StoredProcedure;
                sqlcommand.ExecuteNonQuery();
                sqlcommand.Dispose();
                ObjCon.Close();
            }
            catch (Exception e)
            {
                m_util.write_log("UpdateReQuestTbl:" + e.ToString(), 3);
                InsertErrorLog(e.ToString(), "DB", "UpdateReQuestTbl", 2);
            }
        }

        public void InsertChargingTbl(Util.TCharging m_tCharging)
        {
            try
            {
                SqlConnection ObjCon = new SqlConnection(conn);
                ObjCon.Open();
                SqlCommand sqlcommand = new SqlCommand("USSD_Insert_ChargingTbl", ObjCon);
                //(@StartTime datetime,@MSISDN nchar(15),@SessionID nchar(50),@Service_ID int,@ErrorCode int,@Cost int,@ErrorDescription nchar(100))
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@StartTime", SqlDbType.DateTime));
                sqlcommand.Parameters["@StartTime"].Value = m_tCharging.StartTime;
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@MSISDN", SqlDbType.NChar));
                sqlcommand.Parameters["@MSISDN"].Value = m_tCharging.UserMSISDN;
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@SessionID", SqlDbType.NChar));
                sqlcommand.Parameters["@SessionID"].Value = m_tCharging.SessionID;
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Service_ID", SqlDbType.Int));
                sqlcommand.Parameters["@Service_ID"].Value = m_tCharging.Service_ID;
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ErrorCode", SqlDbType.Int));
                sqlcommand.Parameters["@ErrorCode"].Value = m_tCharging.ErrorCode;
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Cost", SqlDbType.Int));
                sqlcommand.Parameters["@Cost"].Value = m_tCharging.Cost;
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ErrorDescription", SqlDbType.Char));
                sqlcommand.Parameters["@ErrorDescription"].Value = m_tCharging.ErrorDescription;
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@User_ID", SqlDbType.NChar));
                sqlcommand.Parameters["@User_ID"].Value = m_tCharging.User_ID;
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CDRIndicator", SqlDbType.Char));
                sqlcommand.Parameters["@CDRIndicator"].Value = m_tCharging.CDRIndicator;
                sqlcommand.CommandType = CommandType.StoredProcedure;
                sqlcommand.ExecuteNonQuery();
                sqlcommand.Dispose();
                ObjCon.Close();
            }
            catch (Exception e)
            {
                m_util.write_log("InsertChargingTbl:" + e.ToString(), 3);
                InsertErrorLog(e.ToString(), "DB", "InsertChargingTbl", 2);

            }
        }
        public int GetCostByService(int ServiceID)
        {
            int Cost = 0;
            try
            {
                SqlConnection ObjCon = new SqlConnection(conn);
                ObjCon.Open();
                SqlCommand sqlcommand = new SqlCommand("USSD_GetCostByService", ObjCon);
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ServiceID", SqlDbType.Int));
                sqlcommand.Parameters["@ServiceID"].Value = ServiceID;
                sqlcommand.CommandType = CommandType.StoredProcedure;
                SqlDataReader reader = sqlcommand.ExecuteReader();
                reader.Read();
                if (!reader.HasRows)
                {
                    Cost = 0;
                }
                else
                {
                    Cost = reader.GetInt32(0);
                }
                reader.Dispose();
                sqlcommand.Dispose();
                ObjCon.Close();
            }
            catch (Exception e1)
            {
                m_util.write_log("GetCostByService:" + e1.ToString(), 3);
                InsertErrorLog(e1.ToString(), "DB", "GetCostByService", 2);
            }
            return Cost;
        }
        public int GetUserOnline(string MSISDN, string User_ID)
        {
            int ID = 0;
            try
            {
                SqlConnection ObjCon = new SqlConnection(conn);
                ObjCon.Open();
                SqlCommand sqlcommand = new SqlCommand("USSD_CheckUserOnline", ObjCon);
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@MSISDN", SqlDbType.NChar));
                sqlcommand.Parameters["@MSISDN"].Value = MSISDN;
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@User_ID", SqlDbType.NChar));
                sqlcommand.Parameters["@User_ID"].Value = User_ID;
                sqlcommand.CommandType = CommandType.StoredProcedure;
                SqlDataReader reader = sqlcommand.ExecuteReader();
                reader.Read();
                if (!reader.HasRows)
                {
                    ID = 0;
                }
                else
                {
                    ID = Int32.Parse(reader.GetValue(0).ToString());
                }
                reader.Dispose();
                sqlcommand.Dispose();
                ObjCon.Close();
            }
            catch (Exception e1)
            {
                m_util.write_log("GetUserOnline:" + e1.ToString(), 3);
                InsertErrorLog(e1.ToString(), "DB", "GetUserOnline", 2);
            }

            return ID;
        }
        public DataSet GetServiceByPage(int MainPage)
        {
            DataSet ds = new DataSet();
            try
            {
                SqlConnection ObjCon = new SqlConnection(conn);
                ObjCon.Open();
                SqlCommand sqlcommand = new SqlCommand("USSD_Get_MainPage", ObjCon);
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@MainPage", SqlDbType.Int));
                sqlcommand.Parameters["@MainPage"].Value = MainPage;
                sqlcommand.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter objda = new SqlDataAdapter(sqlcommand);
                objda.Fill(ds);
                objda.Dispose();
                ObjCon.Close();
            }
            catch (Exception e1)
            {
                m_util.write_log("GetServiceByPage:" + e1.ToString(), 3);
                InsertErrorLog(e1.ToString(), "DB", "GetUserOnline", 2);
            }
            return ds;
        }
        public void InsertErrorLog(string Error, string ErrorType, string functionError, int ProssesID)
        {
            try
            {
                //@Error varchar(500), @ErrorType varchar(50),@functionError varchar(50),@ProssesID int
                SqlConnection ObjCon = new SqlConnection(conn);
                ObjCon.Open();
                SqlCommand sqlcommand = new SqlCommand("InsertLogTbl", ObjCon);
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Error", SqlDbType.VarChar));
                sqlcommand.Parameters["@Error"].Value = Error;
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ErrorType", SqlDbType.VarChar));
                sqlcommand.Parameters["@ErrorType"].Value = ErrorType;
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@functionError", SqlDbType.VarChar));
                sqlcommand.Parameters["@functionError"].Value = functionError;
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ProssesID", SqlDbType.Int));
                sqlcommand.Parameters["@ProssesID"].Value = ProssesID;
                sqlcommand.CommandType = CommandType.StoredProcedure;
                sqlcommand.ExecuteNonQuery();
                sqlcommand.Dispose();
                ObjCon.Close();
            }
            catch (Exception e)
            {
                m_util.write_log("InsertErrorLog:" + e.ToString(), 3);
            }
        }
        #region BD
        public DataSet GetListMathByGiaiDau(int giaidauid)
        {
            DataSet ds = new DataSet();
            try
            {
                SqlConnection ObjCon = new SqlConnection(conn_data);
                ObjCon.Open();
                SqlCommand sqlcommand = new SqlCommand("USSD_Get_ListMatch_Giaidau", ObjCon);
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@giaidauid", SqlDbType.Int));
                sqlcommand.Parameters["@giaidauid"].Value = giaidauid;
                sqlcommand.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter objda = new SqlDataAdapter(sqlcommand);
                objda.Fill(ds);
                objda.Dispose();
                ObjCon.Close();
            }
            catch (Exception e)
            {
                m_util.write_log("GetListMathByGiaiDau:" + e.ToString(), 3);
                InsertErrorLog(e.ToString(), "DB", "GetListMathByGiaiDau", 2);
            }
            return ds;
        }
        public DataSet GetLTDByGiaiDau(int giaidauid)
        {
            DataSet ds = new DataSet();
            try
            {
                SqlConnection ObjCon = new SqlConnection(conn_data);
                ObjCon.Open();
                SqlCommand sqlcommand = new SqlCommand("USSD_Get_LTD_Giaidau", ObjCon);
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@giaidauid", SqlDbType.Int));
                sqlcommand.Parameters["@giaidauid"].Value = giaidauid;
                sqlcommand.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter objda = new SqlDataAdapter(sqlcommand);
                objda.Fill(ds);
                objda.Dispose();
                ObjCon.Close();
            }
            catch (Exception e)
            {
                m_util.write_log("GetLTDByGiaiDau:" + e.ToString(), 3);
                InsertErrorLog(e.ToString(), "DB", "GetLTDByGiaiDau", 2);
            }
            return ds;
        }
        public DataSet GetTLByGiaiDau(int giaidauid)
        {
            DataSet ds = new DataSet();
            try
            {
                SqlConnection ObjCon = new SqlConnection(conn_data);
                ObjCon.Open();
                SqlCommand sqlcommand = new SqlCommand("USSD_GetTL_GIAIDAU", ObjCon);
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@giaidauid", SqlDbType.Int));
                sqlcommand.Parameters["@giaidauid"].Value = giaidauid;
                sqlcommand.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter objda = new SqlDataAdapter(sqlcommand);
                objda.Fill(ds);
                objda.Dispose();
                ObjCon.Close();
            }
            catch (Exception e)
            {
                m_util.write_log("GetTLByGiaiDau:" + e.ToString(), 3);
                InsertErrorLog(e.ToString(), "DB", "GetTLByGiaiDau", 2);
            }
            return ds;
        }
        public DataSet GetBXHByGiaiDau(int giaidauid)
        {
            DataSet ds = new DataSet();
            try
            {
                SqlConnection ObjCon = new SqlConnection(conn_data);
                ObjCon.Open();
                SqlCommand sqlcommand = new SqlCommand("USSD_GetBXH", ObjCon);
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@giaidauid", SqlDbType.Int));
                sqlcommand.Parameters["@giaidauid"].Value = giaidauid;
                sqlcommand.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter objda = new SqlDataAdapter(sqlcommand);
                objda.Fill(ds);
                objda.Dispose();
                ObjCon.Close();
            }
            catch (Exception e)
            {
                m_util.write_log("GetBXHByGiaiDau:" + e.ToString(), 3);
                InsertErrorLog(e.ToString(), "DB", "GetBXHByGiaiDau", 2);
            }
            return ds;
        }
        public DataSet GetListGiaiDauKhac()
        {
            DataSet ds = new DataSet();
            try
            {
                SqlConnection ObjCon = new SqlConnection(conn_data);
                ObjCon.Open();
                SqlCommand sqlcommand = new SqlCommand("USSD_Get_GIAIDAU_KHAC", ObjCon);
                sqlcommand.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter objda = new SqlDataAdapter(sqlcommand);
                objda.Fill(ds);
                objda.Dispose();
                ObjCon.Close();
            }
            catch (Exception e)
            {
                m_util.write_log("GetListGiaiDauKhac:" + e.ToString(), 3);
                InsertErrorLog(e.ToString(), "DB", "GetListGiaiDauKhac", 2);
            }
            return ds;
        }
        #endregion BD
        #region XS
        public string GetXsByTinhDate(string Tinhid, string date)
        {
            string Result = "";
            try
            {
                SqlConnection ObjCon = new SqlConnection(conn_data);
                ObjCon.Open();
                SqlCommand sqlcommand = new SqlCommand("USSD_GetXsByTinh_GetOfDay", ObjCon);
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@tinhid", SqlDbType.VarChar));
                sqlcommand.Parameters["@tinhid"].Value = Tinhid;
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@dates", SqlDbType.VarChar));
                sqlcommand.Parameters["@dates"].Value = date;
                sqlcommand.CommandType = CommandType.StoredProcedure;
                SqlDataReader reader = sqlcommand.ExecuteReader();
                reader.Read();
                if (!reader.HasRows)
                {
                    Result = "0";
                }
                else
                {
                    Result = reader.GetValue(2).ToString();
                }
                reader.Dispose();
                sqlcommand.Dispose();
                ObjCon.Close();
            }
            catch (Exception e1)
            {
                m_util.write_log("GetXsByTinhDate:" + e1.ToString(), 3);
                InsertErrorLog(e1.ToString(), "DB", "GetXsByTinhDate", 2);
            }
            return Result;
        }
        public string GetXsByTinh(string Tinhid)
        {
            string Result = "";
            try
            {
                SqlConnection ObjCon = new SqlConnection(conn_data);
                ObjCon.Open();
                SqlCommand sqlcommand = new SqlCommand("USSD_GetXsByTinh", ObjCon);
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@tinhid", SqlDbType.VarChar));
                sqlcommand.Parameters["@tinhid"].Value = Tinhid;
                sqlcommand.CommandType = CommandType.StoredProcedure;
                SqlDataReader reader = sqlcommand.ExecuteReader();
                reader.Read();
                if (!reader.HasRows)
                {
                    Result = "0";
                }
                else
                {
                    string nam = reader.GetValue(1).ToString().Substring(0, 4);
                    string matinh = "";
                    string matinh_moi = "";
                    matinh = reader.GetValue(4).ToString();
                    matinh_moi = reader.GetValue(5).ToString();
                    Result = reader.GetValue(2).ToString().Replace(matinh, matinh_moi + "<>");
                    Result = Result.Replace("n" + nam, "");
                }
                reader.Dispose();
                sqlcommand.Dispose();
                ObjCon.Close();
            }
            catch (Exception e1)
            {
                m_util.write_log("GetXsByTinhDate:" + e1.ToString(), 3);
                InsertErrorLog(e1.ToString(), "DB", "GetXsByTinhDate", 2);
            }

            return Result;
        }
        public DataSet GetListTinhToDay(int region)
        {
            DataSet ds = new DataSet();
            try
            {
                SqlConnection ObjCon = new SqlConnection(conn_data);
                ObjCon.Open();
                SqlCommand sqlcommand = new SqlCommand("USSD_ListTinh_GetOfDay", ObjCon);
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@region", SqlDbType.Int));
                sqlcommand.Parameters["@region"].Value = region;
                sqlcommand.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter objda = new SqlDataAdapter(sqlcommand);
                objda.Fill(ds);
                objda.Dispose();
                ObjCon.Close();
            }
            catch (Exception e)
            {
                m_util.write_log("GetListTinhToDay:" + e.ToString(), 3);
                InsertErrorLog(e.ToString(), "DB", "GetListTinhToDay", 2);
            }

            return ds;
        }
        #endregion XS
        #region TruyenCuoi

        public DataSet GetListTruyenHot(string dest_addr)
        {
            DataSet ds = new DataSet();
            try
            {
                SqlConnection ObjCon = new SqlConnection(conn_data);
                ObjCon.Open();
                SqlCommand sqlcommand = new SqlCommand("USSD_STORY_GetTopHot", ObjCon);
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@dest_addr", SqlDbType.VarChar));
                sqlcommand.Parameters["@dest_addr"].Value = dest_addr;
                sqlcommand.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter objda = new SqlDataAdapter(sqlcommand);
                objda.Fill(ds);
                objda.Dispose();
                ObjCon.Close();
            }
            catch (Exception e)
            {
                m_util.write_log("GetListTruyenHot:" + e.ToString(), 3);
                InsertErrorLog(e.ToString(), "DB", "GetListTruyenHot", 2);
            }
            return ds;
        }

        public DataSet GetListTruyenVui(string dest_addr)
        {
            DataSet ds = new DataSet();
            try
            {
                SqlConnection ObjCon = new SqlConnection(conn_data);
                ObjCon.Open();
                SqlCommand sqlcommand = new SqlCommand("USSD_STORY_GetTopVui", ObjCon);
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@dest_addr", SqlDbType.VarChar));
                sqlcommand.Parameters["@dest_addr"].Value = dest_addr;
                sqlcommand.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter objda = new SqlDataAdapter(sqlcommand);
                objda.Fill(ds);
                objda.Dispose();
                ObjCon.Close();
            }
            catch (Exception e)
            {
                m_util.write_log("GetListTruyenVui:" + e.ToString(), 3);
                InsertErrorLog(e.ToString(), "DB", "GetListTruyenVui", 2);
            }
            return ds;

        }
        public void InsertCustumerStory(string dest_addr, int StoryID)
        {
            try
            {
                SqlConnection ObjCon = new SqlConnection(conn);
                ObjCon.Open();
                SqlCommand sqlcommand = new SqlCommand("USSD_STORY_CUSTOMER_Insert", ObjCon);
                //(@StartTime datetime,@MSISDN nchar(15),@SessionID nchar(50),@Service_ID int,@ErrorCode int,@Cost int,@ErrorDescription nchar(100))
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@dest_addr", SqlDbType.VarChar));
                sqlcommand.Parameters["@dest_addr"].Value = dest_addr;
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@StoryID", SqlDbType.Int));
                sqlcommand.Parameters["@StoryID"].Value = StoryID;
                sqlcommand.CommandType = CommandType.StoredProcedure;
                sqlcommand.ExecuteNonQuery();
                sqlcommand.Dispose();
                ObjCon.Close();
            }
            catch (Exception e)
            {
                m_util.write_log("InsertCustumerStory:" + e.ToString(), 3);
                InsertErrorLog(e.ToString(), "DB", "InsertCustumerStory", 2);
            }

        }
        public string GetTruyenByID(int ID_truyen)
        {
            string Result = "";
            try
            {
                SqlConnection ObjCon = new SqlConnection(conn_data);
                ObjCon.Open();
                SqlCommand sqlcommand = new SqlCommand("USSD_GetTruyenByID", ObjCon);
                sqlcommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ID_truyen", SqlDbType.Int));
                sqlcommand.Parameters["@ID_truyen"].Value = ID_truyen;
                sqlcommand.CommandType = CommandType.StoredProcedure;
                SqlDataReader reader = sqlcommand.ExecuteReader();
                reader.Read();
                if (!reader.HasRows)
                {
                    Result = "0";
                }
                else
                {
                    Result = reader.GetValue(0).ToString();
                }
                reader.Dispose();
                sqlcommand.Dispose();
                ObjCon.Close();
            }
            catch (Exception e1)
            {
                m_util.write_log("GetTruyenByID:" + e1.ToString(), 3);
                InsertErrorLog(e1.ToString(), "DB", "GetTruyenByID", 2);
            }
            Result = m_util.Convert2assi(Result);
            return Result;
        }
        #endregion TruyenCuoi
        #region TiGia
        public DataSet GetGiaVang()
        {
            DataSet ds = new DataSet();
            try
            {
                SqlConnection ObjCon = new SqlConnection(conn_data);
                ObjCon.Open();
                SqlCommand sqlcommand = new SqlCommand("USSD_GiaVang_GetByDay", ObjCon);
                sqlcommand.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter objda = new SqlDataAdapter(sqlcommand);
                objda.Fill(ds);
                objda.Dispose();
                ObjCon.Close();
            }
            catch (Exception e)
            {
                m_util.write_log("GetGiaVang:" + e.ToString(), 3);
                InsertErrorLog(e.ToString(), "DB", "GetGiaVang", 2);
            }
            return ds;
        }
        public DataSet GetGiaNT()
        {
            DataSet ds = new DataSet();
            try
            {
                SqlConnection ObjCon = new SqlConnection(conn_data);
                ObjCon.Open();
                SqlCommand sqlcommand = new SqlCommand("USSD_GiaNT_GetByDay", ObjCon);
                sqlcommand.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter objda = new SqlDataAdapter(sqlcommand);
                objda.Fill(ds);
                objda.Dispose();
                ObjCon.Close();
            }
            catch (Exception e)
            {
                m_util.write_log("GetGiaNT:" + e.ToString(), 3);
                InsertErrorLog(e.ToString(), "DB", "GetGiaNT", 2);
            }
            return ds;
        }
        #endregion TiGia
    }
}
